package com.my.socket.nio.v31;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

/**
 * Created by ZhongGang
 * at 2018/8/21 11:03
 */
public class Client {
    private static final Logger LOGGER = LoggerFactory.getLogger(Client.class);

    public static void main(String[] args) throws Exception {
        Socket socket = new Socket();
        socket.connect(new InetSocketAddress("127.0.0.1", 9999));

        OutputStream outputStream = socket.getOutputStream();
        String request = "I am Alex";
        outputStream.write(request.getBytes());
        socket.shutdownOutput();
        LOGGER.info("write: {}", request);

        InputStream inputStream = socket.getInputStream();
        byte[] bytes = new byte[1024];
        inputStream.read(bytes);
        socket.shutdownInput();
        LOGGER.info("read: {}", new String(bytes));
    }
}
